package com.iot08.api.service.sms;

import com.alibaba.fastjson.JSON;
import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.iot08.common.entity.app.sms.SendSmsResponseWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @description: 阿里云短信云平台推送消息
 * @author: chenwenjie
 * @date: 2023/6/29 10:21
 * @param:
 * @return:
 **/
@Service
public class AliYunSmsServiceImpl implements IProviderSmsService {
    private static final Logger logger = LoggerFactory.getLogger(AliYunSmsServiceImpl.class);

    private static final String signName = "一路守护";

    private final Client client;

    public AliYunSmsServiceImpl(Client client) {
        this.client = client;
    }


    /**
     * @description 发送短信
     * @author cwj
     * @param [mobile, param, configMap]
     * @return com.iot08.common.entity.app.sms.SendSmsResponseWrapper
     * @date @time 2025/5/9 14:30
     **/
    @Override
    public SendSmsResponseWrapper send(String mobile, Object param, Map<String, String> configMap) throws Exception {
        logger.info("短信发送签名：{}，短信发送模板{}，硬编码的签名：{}", configMap.get("signName"), configMap.get("templateCode"), signName);
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setPhoneNumbers(mobile)
                .setSignName(configMap.get("signName"))
                .setTemplateCode(configMap.get("templateCode"))
                .setTemplateParam(JSON.toJSONString(param));
        SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
        logger.debug("阿里云短信平台响应体: {}" , JSON.toJSONString(sendSmsResponse));
        return new SendSmsResponseWrapper(sendSmsResponse.getBody()) ;
    }

   /* @Override
    public SendSmsResponseWrapper sendNotify(String mobile, Object param, Map<String, String> configMap) throws Exception {
        logger.info("短信发送签名：{}，短信发送模板{}，硬编码的签名：{}", configMap.get("signName"), configMap.get("templateCode"), signName);
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setPhoneNumbers(mobile)
                .setSignName(configMap.get("signName"))
                .setTemplateCode(configMap.get("templateCode"))
                .setTemplateParam(JSON.toJSONString(param));
        SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
        logger.debug("阿里云短信平台响应体: {}" , JSON.toJSONString(sendSmsResponse));
        return new SendSmsResponseWrapper(sendSmsResponse.getBody()) ;
    }*/
}
